import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm";

@Index("openid", ["openid"], { unique: true })
@Index("phone", ["phone"], { unique: true })
@Entity("user", { schema: "base" })
export class User {
  @PrimaryGeneratedColumn({ type: "int", name: "id", unsigned: true })
  id: number;

  @Column("varchar", { name: "openid", unique: true, length: 30 })
  openid: string;

  @Column("varchar", { name: "nickname", length: 50 })
  nickname: string;

  @Column("varchar", { name: "avatar", length: 100 })
  avatar: string;

  @Column("json", { name: "albums", nullable: true, comment: "相册" })
  albums: object | null;

  @Column("char", { name: "phone", nullable: true, unique: true, length: 11 })
  phone: string | null;

  @Column("tinyint", { name: "source", default: () => "'0'" })
  source: number;

  @Column("decimal", {
    name: "amount",
    precision: 6,
    scale: 2,
    default: () => "'0.00'",
  })
  amount: string;

  @Column("decimal", {
    name: "reward_amount",
    precision: 6,
    scale: 2,
    default: () => "'0.00'",
  })
  rewardAmount: string;

  @Column("decimal", {
    name: "freeze_amount",
    precision: 6,
    scale: 2,
    default: () => "'0.00'",
  })
  freezeAmount: string;

  @Column("int", {
    name: "register_time",
    unsigned: true,
    default: () => "'0'",
  })
  registerTime: number;

  @Column("int", {
    name: "last_login_time",
    unsigned: true,
    default: () => "'0'",
  })
  lastLoginTime: number;

  @Column("varchar", { name: "last_ip", nullable: true, length: 15 })
  lastIp: string | null;
}
